package com.cqc.phoneinfo;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;


public class MainActivity extends AppCompatActivity {
    private static TelephonyManager tm;
    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        context = this;

        get();
    }

    public void get(){
        tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
//      sim
        String simOperator = tm.getSimOperator();//sim卡提供商编码
        String simSerialNumber = tm.getSimSerialNumber();//sim卡序列号
        String simOperatorName = tm.getSimOperatorName();//sim提供商名称
        String simCountryIso = tm.getSimCountryIso();//sim国家编码
        int simState = tm.getSimState();//sim卡状态
        String line1Number = tm.getLine1Number();//本机号码(一般获取不到)

//      Device
        String deviceId = tm.getDeviceId();//设备编号
        String deviceSoftwareVersion = (tm.getDeviceSoftwareVersion() == null)? tm.getDeviceSoftwareVersion() : "未知版本";//系统平台版本

//      Network
        String networkOperator = tm.getNetworkOperator();//网络提供商编号
        String networkOperatorName = tm.getNetworkOperatorName();//网络提供商名称
        String networkCountryIso = tm.getNetworkCountryIso();//网络提供商国家编码
        int networkType = tm.getNetworkType();//网络类型

        int phoneType = tm.getPhoneType();//手机类型:PHONE_TYPE_NONE + PHONE_TYPE_GSM + PHONE_TYPE_CDMA + PHONE_TYPE_SIP

        String location = tm.getCellLocation().toString() == null ? tm.getCellLocation().toString() : "未知地址";//地址(一般获取不到)

        Log.d("TAG","simOperator="+simOperator
                +"\n"+"simSerialNumber="+simSerialNumber
                +"\n"+"simOperatorName="+simOperatorName
                +"\n"+"simCountryIso="+simCountryIso
                +"\n"+"simState="+simState
                +"\n"+"line1Number="+line1Number
                +"\n"+"deviceId="+deviceId
                +"\n"+"deviceSoftwareVersion="+deviceSoftwareVersion
                +"\n"+"networkOperator="+networkOperator
                +"\n"+"networkOperatorName="+networkOperatorName
                +"\n"+"networkCountryIso="+networkCountryIso
                +"\n"+"networkType="+networkType
                +"\n"+"phoneType="+phoneType
                +"\n"+"location="+location
        );
    }
}
